-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add auto_grown_mutex for selected rows #11012
add auto_grown_mutex for selected rows #11012
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@@ -46,11 +48,13 @@ class SelectedRows { | |||
SelectedRows(const std::vector<int64_t>& rows, const int64_t& height) | |||
: rows_(rows), height_(height) { | |||
value_.reset(new Tensor()); | |||
auto_grown_mutex_.reset(new std::mutex); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we need a TODO here, make variable thread-safe completely.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will give a detailed explanation later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
project: #10868
为什么mutex要放到 unique_ptr中?
https://stackoverflow.com/questions/30340029/copy-class-with-stdmutex
https://stackoverflow.com/questions/37172050/copy-or-move-constructor-for-a-class-with-a-member-stdmutex-or-other-non-copy
Paddle/paddle/fluid/operators/math/selected_rows_functor.h
Lines 70 to 86 in 654f5d3
上面的代码,会在函数内部构造一个selected_rows, 然后return回来,如果selected rows里面有个成员是mutex,他不会生成一个默认的移动构造函数,编译上述functor的时候会挂,如果放到一个unique_prt里边,他会默认调用移动构造函数,把unique_ptr中的指针移动出来。